/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.webcat.electronicsubmissionplugin.utils;

import java.util.ArrayList;
import java.io.File;
import java.util.List;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *  Tests for the Utils class
 *  @author rob44, samccarn, rstodd13
 *  @version 2011.04.30
 */
public class UtilsTest {

    // ----------------------------------------------------------
    /**
     * Create a new UtilsTest object.
     */
    public UtilsTest() {
        //do nothing
    }
    /**
     * Test of readStringFormat method, of class Utils.
     */
    @Test
    public void testReadStringFormat() {
        String str = "&name=null&name=CS 2114";
        String storeName = "name";
        List<String> expResult = new ArrayList<String>();
        List<String> result = Utils.readStringFormat(str, storeName);
        expResult.add("nll");
        expResult.add("CS 2114");
        assertEquals(expResult, result);
    }

    /**
     * Test of storeStringFormat method, of class Utils.
     */
    @Test
    public void testStoreStringFormat() {
        List<String> list = new ArrayList<String>();
        list.add("h");
        list.add("llo");
        String storeName = "greeting";
        String expResult = "&greeting=h&greeting=llo";
        String result = Utils.storeStringFormat(list, storeName);
        assertEquals(expResult, result);
    }

    /**
     * Test of createTempFile method, of class Utils.
     */
    @Test
    public void testCreateTempFile() {
        String content = "a";
        String expResult = System.getProperty("user.dir") + "/tempWebCatFile.html";
        String result = Utils.createTempFile(content);
        assertEquals(expResult, result);
    }

    /**
     * Test of writeToFile method, of class Utils.
     */
    @Test
    public void testWriteToFile() {
        File file = new File("testWriteTo.txt");
        String toWrite = "hello";
        Utils.writeToFile(file, toWrite);
        assertEquals(5, file.length());
    }

}